package cn.acewill.yxd.yunxundian.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import cn.acewill.yxd.yunxundian.R;
import cn.acewill.yxd.yunxundian.model.SchAddBean;

/**
 * Created by he on 2017/4/17.
 */

public class SchAddPanelAdapter extends BaseAdapter {
    private List<SchAddBean> mList;
    private ArrayList<SchAddBean> mOriginalValues;
    private Context mContext;
    private LayoutInflater mInflater;
    private int year;
    private int month;
    private int day;
    private moreTaskCallBack moreTaskCallBack;

    private final Object mLock = new Object();
    //是否可点击时间选择
    private Boolean iscanClick = true;


    public SchAddPanelAdapter(Context context,List<SchAddBean> list, moreTaskCallBack moreTaskCallBack){
        mList = list;
        mContext = context;
        mInflater = LayoutInflater.from(context);
        this.moreTaskCallBack=moreTaskCallBack;
        iscanClick = true;
    }
    public SchAddPanelAdapter(Context context,List<SchAddBean> list){
        mList = list;
        mContext = context;
        mInflater = LayoutInflater.from(context);
        iscanClick = false;
    }
    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return mList==null?0:mList.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        SchAddPanelAdapter.ViewHolder holder = null;
        final SchAddBean bean=mList.get(position);
        if (convertView == null) {
            holder=new SchAddPanelAdapter.ViewHolder();

            convertView = mInflater.inflate(R.layout.schaddpanel, null);
            holder.mTitle = (TextView)convertView.findViewById(R.id.schTitle);
            holder.mSubTitile = (TextView) convertView.findViewById(R.id.schMainTitleEdit);
            holder.mSchDate=(TextView)convertView.findViewById(R.id.schStartDate);
            holder.mSchTime=(TextView)convertView.findViewById(R.id.schStartTime);
            convertView.setTag(holder);
        }else {

            holder = (SchAddPanelAdapter.ViewHolder)convertView.getTag();
        }

        holder.mTitle.setText((String)mList.get(position).getSchTypeStr());
        holder.mSubTitile.setText((String)mList.get(position).getShopname());
        if(mList.get(position).getSchStartTime()!=null) {
            holder.mSchDate.setText(mList.get(position).getSchStartTime().toString().split("T")[0]);
            holder.mSchTime.setText(mList.get(position).getSchStartTime().toString().split("T")[1]);
        }
        if (iscanClick == true){

        holder.mSchDate.setTag(position);
        holder.mSchDate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                moreTaskCallBack.Click(bean,v,position);
            }
        });
        holder.mSchTime.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                moreTaskCallBack.Click(bean,v,position);
            }
        });
        }
        return convertView;
    }

    public interface moreTaskCallBack{
        void Click(SchAddBean bean,View v,int pid);
    }

    public class ViewHolder{
        public TextView mTitle;
        public TextView mSubTitile;
        public TextView mSchDate;
        public TextView mSchTime;

    };
}
